


//
//  CAKeyframeAnimationController.m
//  界面动画集
//
//  Created by YYY on 2017/7/3.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "CAKeyframeAnimationController.h"

@interface CAKeyframeAnimationController ()
{
    NSArray *transformArray;
}

@property(nonatomic,strong)CALayer *layer;

@end

@implementation CAKeyframeAnimationController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"CAKeyframeAnimation";
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    transformArray = @[@"scale缩放",@"",@""];
    
    [self.view.layer addSublayer:self.layer];
    for (int i=0; i<transformArray.count; i++)
    {
        UIButton *transform = [UIButton buttonWithType:UIButtonTypeCustom];
        transform.frame = CGRectMake(10+i*100, 70, 90, 30);
        [transform setTitle:transformArray[i] forState:UIControlStateNormal];
        transform.titleLabel.font = [UIFont systemFontOfSize:14];
        [transform setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [transform addTarget:self action:@selector(transformAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:transform];
    }
    // Do any additional setup after loading the view.
}

-(CALayer *)layer
{
    if (!_layer)
    {
        _layer = [[CALayer alloc]init];
        //_layer.position = self.view.layer.position;
        _layer.frame = CGRectMake(50, 200, 100, 100);
        //_layer.backgroundColor = [UIColor purpleColor].CGColor;
        _layer.cornerRadius = 10;
        _layer.shadowOffset = CGSizeMake(4, 4);
        _layer.shadowColor = [UIColor redColor].CGColor;
        _layer.shadowOpacity = 0.7;
        _layer.shadowRadius = 12;
        _layer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pear"]].CGColor;
        
    }
    return _layer;
}
-(void)transformAction:(UIButton *)transformBtn
{
    if([transformBtn.currentTitle isEqualToString:@"scale缩放"])
    {
        CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        scaleAnimation.duration = 2.0;
        scaleAnimation.values = @[@(1.2),@(0.8),@(1)];
        scaleAnimation.calculationMode = kCAAnimationCubicPaced;
        [self.layer addAnimation:scaleAnimation forKey:nil];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
